package cn.iocoder.yudao.module.system.jgpush;

import cn.jiguang.sdk.api.PushApi;
import cn.jiguang.sdk.bean.push.PushSendParam;
import cn.jiguang.sdk.bean.push.PushSendResult;
import cn.jiguang.sdk.bean.push.audience.Audience;
import cn.jiguang.sdk.bean.push.message.notification.NotificationMessage;
import cn.jiguang.sdk.constants.ApiConstants;

import java.util.List;

public class PushSendUtil {


    public static   void send(List<String> aliasList,String alert){
        if (aliasList == null || aliasList.isEmpty()) {
            throw new IllegalArgumentException("接收者列表不能为空");
        }
        PushApi instance = PushApiFactory.getInstance();
        PushSendParam pushSendParam = new PushSendParam();
        //发送平台
        pushSendParam.setPlatform(ApiConstants.Platform.ALL);
        //受众
        Audience audience = new Audience();
        audience.setAliasList(aliasList);
        pushSendParam.setAudience(audience);
        //notification通知
        NotificationMessage notificationMessage = new NotificationMessage();
        notificationMessage.setAlert(alert);
        pushSendParam.setNotification(notificationMessage);
        //处理 有的员工还没有登陆过app，无法发送过去，直接捕获异常
        try {
            PushSendResult send = instance.send(pushSendParam);
            System.out.println(send);
        }catch (Exception e){
        }
    }

    public static void main(String[] args) {
        PushApi instance = PushApiFactory.getInstance();
        PushSendParam pushSendParam = new PushSendParam();
        //发送平台
        pushSendParam.setPlatform("all");
        //受众
        Audience audience = new Audience();
        audience.setAliasList(List.of("epos_app_user_2"));
        pushSendParam.setAudience(audience);
        //notification通知
        NotificationMessage notificationMessage = new NotificationMessage();
        notificationMessage.setAlert("恭喜你中奖了100亿！");
        pushSendParam.setNotification(notificationMessage);

        PushSendResult send = instance.send(pushSendParam);
        System.out.println(send);
    }
}
